#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main( int argc, char *argv[] )
{
	int c;
	int hFlag = 0, tFlag = 0, errFlag = 0;
	char *text;
	extern char *optarg;
    extern int optind, optopt;
	while((c = getopt(argc, argv, "ht:")) != -1) {
		switch(c) {
		case 'h':
			hFlag++;
			break;
		case 't':
			tFlag++;
			text = optarg;
			break;
		case '?':
			printf("Unrecognized option: -%c\n", optopt);
			errFlag++;
		}
	}
	if(errFlag || hFlag && tFlag || !hFlag && !tFlag) {
		printf("usage: read_args -h|-t text\n");
		exit(2);
	}
	if(hFlag) {
		printf("usage: read_args -h|-t text\nOptions:\n");
		printf("-h prints instructions\n");
		printf("-t prints the given text\n");
	}
	if(tFlag) {
		printf("%s\n", text);
	}
}
